//
//  MySearchBar.m
//  MyShoppingApp
//
//  Created by ibokan on 16/1/11.
//  Copyright © 2016年 ibokan. All rights reserved.
//

#import "YJSearchBar.h"
#import "UIImage+Extension.h"
@implementation YJSearchBar
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {

       self.placeholder = @"搜索";
        self.font = [UIFont systemFontOfSize:13.0f];
        self.clearButtonMode = UITextFieldViewModeAlways;
        UIImage *backImage =[UIImage imageNamed:@"searchBarBackground"];
        NSInteger leftCapWidth = backImage.size.width * 0.5;
        NSInteger topCapHeight = backImage.size.height * 0.5;
        backImage = [backImage stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight];
        self.background = backImage;
        //左边图标
        UIImageView *searchIcon = [[UIImageView alloc]init];
        searchIcon.image = [UIImage imageNamed:@"search"];
        //设置该模式下，图片保持原样，不会拉伸，并且居中
        searchIcon.contentMode = UIViewContentModeCenter;
        searchIcon.width = 30;
        searchIcon.height = 30;
        self.leftView = searchIcon;
        self.leftViewMode = UITextFieldViewModeAlways;
    }
    return self;
}

+(instancetype)searchBar
{
    return [[self alloc]init];
}

@end
